package com.gxa.web.ServiceManagement;


import com.alibaba.fastjson.JSONObject;
import com.gxa.common.R;
import com.gxa.pojo.Problem;
import com.gxa.service.ServiceService;
import com.gxa.service.impl.ServiceServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

//服务管理-添加常见问题
@WebServlet("/service/addManagement")
public class AddServletProcessingServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String ptitle = request.getParameter("ptitle");
        String ptype = request.getParameter("ptype");
        String pauthor = request.getParameter("pauthor");
        String pmethod = request.getParameter("pmethod");
        String pnotes = request.getParameter("pnotes");
        Problem problem = new Problem();

        problem.setPtitle(ptitle);
        problem.setPtype(ptype);
        problem.setPauthor(pauthor);
        problem.setPmethod(pmethod);
        problem.setPnotes(pnotes);
        Date date = new Date();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = df.format(date);
        problem.setPlast_time(str);
        //调用service
        ServiceService serviceService = new ServiceServiceImp();
        R r = serviceService.addServiceManagementById(problem);
        //响应R
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(r));
    }
}
